<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../application/vue.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="切换A" @click="name='compA'">
        <input type="button" value="切换B" @click="name='compB'">
        <hr>
        <!-- <component :is="name" ></component> -->
        <!-- <keep-alive>
            <component :is="name" ></component>
        </keep-alive> -->
        <!-- <keep-alive include="compA,compB"> -->
        <!-- <keep-alive exclude="compA,compB"> -->
        <!-- <keep-alive :exclude="/^compA/"> -->
        <!-- <keep-alive :exclude="/^comp/"> -->
        <keep-alive max=3>
            <component :is="name" ></component>
        </keep-alive>
    </div>
    <template id="compa">
        <div>
            <p>组件A</p>
        </div>
    </template>
    <template id="compb">
        <div>
            <p>组件B</p>
        </div>
    </template>
</body>
<script>
    new Vue({
        el:"#app",
        components:{
            compA:{
                template:"#compa",
                mounted(){
                    console.log("compA被创建");
                },
                destroyed(){
                    console.log("compA被销毁");
                }
            },
            compB:{
                template:"#compb",
                mounted(){
                    console.log("compB被创建");
                },
                destroyed(){
                    console.log("compB被销毁");
                }
            }
        },
        data:{
            name:"compA"
        }
    })
</script>
</html>